package si.yun.web;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import si.yun.entity.SyProduct;
import si.yun.service.OperationService;
import si.yun.utils.JsonData;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description: web层
 * @ClassName OperationController
 * @Author MT
 * @Date 2021/7/29 15:27
 * @Version 1.0
 **/
@RestController
@RequestMapping("/operation")
public class OperationController {
    @Resource
    private OperationService service;

    //查询商品分类父
    @RequestMapping("/selProductCategory")
    public JsonData selProductCategory(){
        List<Map<String, Object>> maps = service.selProductCategory();
        return maps!=null?JsonData.buildSuccess(maps):JsonData.buildError("服务器出错了");
    }

    //获取商品信息
    @RequestMapping("/selProduct")
    public JsonData selProduct(String name1, Integer name2, Integer name3, String name4,Integer name5,Integer product_id,Integer product_code) {
        List<Map<String, Object>> maps = service.selProduct(name1, name2, name3, name4,name5,product_id,product_code);
        return maps!=null?JsonData.buildSuccess(maps):JsonData.buildError("服务器出错了");
    }

    //查询所有商品分类赋值给下拉菜单
    @RequestMapping("/selProductCategorySelect")
    public JsonData selProductCategorySelect() {
        List<Map<String, Object>> maps = service.selProductCategorySelect();
        return maps!=null?JsonData.buildSuccess(maps):JsonData.buildError("服务器出错了");
    }

    //修改商品信息
    @RequestMapping("/updProduct")
    public JsonData updProduct(SyProduct sp) {
        int num= service.updProduct(sp);
        return num>=0?JsonData.buildSuccess(num):JsonData.buildError("服务器出错了");
    }

    //删除商品
    @RequestMapping("/delProduct")
    public JsonData delProduct(Integer productId) {
        int num= service.delProduct(productId);
        return num>=0?JsonData.buildSuccess(num):JsonData.buildError("服务器出错了");
    }

    //统计昨日订单数和昨日销售额度
    @RequestMapping("/selYesterdayOrder")
    public JsonData delProduct() {
        Map<String, Object> map = service.selYesterdayOrder();
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器出错了");
    }

    //统计全部订单数和销售总额
    @RequestMapping("/selAllOrders")
    public JsonData selAllOrders() {
        Map<String, Object> map = service.selAllOrders();
        return map!=null?JsonData.buildSuccess(map):JsonData.buildError("服务器出错了");
    }

    //统计待审核商品总数
    @RequestMapping("/selAuditProduct")
    public JsonData selAuditProduct(Integer AuditProduct) {
        int num = service.selAuditProduct(AuditProduct);
        return num>=0?JsonData.buildSuccess(num):JsonData.buildError("服务器出错了");
    }

    //统计待审核课程
    @RequestMapping("/selAuditCourses")
    public JsonData selAuditCourses(Integer AuditCourses) {
        int num = service.selAuditCourses(AuditCourses);
        return num>=0?JsonData.buildSuccess(num):JsonData.buildError("服务器出错了");
    }

    //统计待审核课程
    @RequestMapping("/selTimeOrder")
    public JsonData selTimeOrder(String datetime) {
        List<Integer> list = service.selTimeOrder(datetime);
        return list!=null?JsonData.buildSuccess(list):JsonData.buildError("服务器出错了");
    }


}
